﻿using System;
using System.Data;

namespace CRS.Web.Reports
{
    public partial class SellDailyReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Session["SellDailySource"] = null;
                Session["GoodssSource"] = null;
                GridView1.DataSource = DataSource;
                GridView1.DataBind();
                GridView2.DataSource = GoodsSource;
                GridView2.DataBind();
            }
        }

        private DataTable DataSource
        {
            get
            {
                if (Session["SellDailySource"] == null)
                {
                    Session["SellDailySource"] = InitData();
                }
                return (DataTable)Session["SellDailySource"];
            }
        }

        private object InitData()
        {
            var table = new DataTable();
            table.Columns.Add("房卡Id");
            table.Columns.Add("房名");
            table.Columns.Add("开始时间");
            table.Columns.Add("结束时间");
            table.Columns.Add("时长");
            table.Columns.Add("单价");
            table.Columns.Add("收费");
            var date = DateTime.Now;
            for (int i = 0; i < 10; i++)
            {
                DataRow row = table.NewRow();
                row["房卡Id"] = "VIC" + i.ToString().PadLeft(10, '0');
                row["房名"] = "雅乐轩" + i.ToString();
                row["开始时间"] = date.ToString("yyyy-MM-dd HH:mm:ss");
                row["结束时间"] = date.AddHours(i*(0.125)).AddMinutes(15).ToString("yyyy-MM-dd HH:mm:ss");
                row["时长"] = Convert.ToDateTime(row["结束时间"])-Convert.ToDateTime(row["开始时间"]);
                row["单价"] = "50";
                var tempPrice = 0.0;
                if (Convert.ToDateTime(row["时长"]).Minute >= 15)
                    tempPrice = (Convert.ToDouble(Convert.ToDateTime(row["时长"]).Minute)/Convert.ToDouble(60))*50.0;
                row["收费"] = string.Format("{0:C2}",(Convert.ToDouble(row["单价"])*((Convert.ToDateTime(row["时长"]).Hour))+tempPrice));
                var ss = Convert.ToDouble(row["收费"].ToString().Replace("￥",""));
                //lblTotal.Text = (Convert.ToDouble(lblTotal.Text) + ss).ToString();
                table.Rows.Add(row);
            }
            //lblTotal.Text = lblTotal.Text + "元";
            return table;
        }

        private DataTable GoodsSource
        {
            get
            {
                if (Session["GoodssSource"] == null)
                {
                    Session["GoodssSource"] = InitDatas();
                }
                return (DataTable)Session["GoodssSource"];
            }
        }

        private object InitDatas()
        {
            var table = new DataTable();
            table.Columns.Add("货品条码");
            table.Columns.Add("货品名称");
            table.Columns.Add("类型");
            table.Columns.Add("数量");
            table.Columns.Add("单价");
            table.Columns.Add("收费");
            table.Columns.Add("清单");
            var date = DateTime.Now;
            for (int i = 1; i < 5; i++)
            {
                DataRow row = table.NewRow();
                row["货品条码"] = "VICode" + i.ToString().PadLeft(5, '0');
                if (i % 5 == 0)
                    row["货品名称"] = "大中华";
                if (i % 5 == 1)
                    row["货品名称"] = "红牛";
                if (i % 5 == 2)
                    row["货品名称"] = "XO";
                if (i % 5 == 3)
                    row["货品名称"] = "可口可乐";
                if (i % 5 == 4)
                    row["货品名称"] = "大红袍";

                if (i % 5 == 0)
                    row["类型"] = "烟类";
                if (i % 5 == 1)
                    row["类型"] = "饮料";
                if (i % 5 == 2)
                    row["类型"] = "酒类";
                if (i % 5 == 3)
                    row["类型"] = "饮料";
                if (i % 5 == 4)
                    row["类型"] = "茶类";
                row["数量"] = i.ToString();

                if (i % 5 == 0)
                    row["单价"] = "90";
                if (i % 5 == 1)
                    row["单价"] = "20";
                if (i % 5 == 2)
                    row["单价"] = "120";
                if (i % 5 == 3)
                    row["单价"] = "8";
                if (i % 5 == 4)
                    row["单价"] = "50";
                row["收费"] = string.Format("{0:C2}", Convert.ToDouble(Convert.ToInt32(row["单价"]) * Convert.ToInt32(row["数量"])));
                var ss = Convert.ToDouble(row["收费"].ToString().Replace("￥", ""));
                //lblGoodsTotal.Text = (Convert.ToDouble(lblGoodsTotal.Text) + ss).ToString();
                table.Rows.Add(row);
            }
            //lblGoodsTotal.Text += "元";
            return table;
        }
    }
}
